package com.umeox.quranplayer.widgets

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.*
import com.umeox.quranplayer.R
import com.umeox.quranplayer.bean.QuranChallenge
import java.util.*

/**
 * Created by Rambo 2021/5/18
 * Describe:
 */
class ChallengeResultDialog(
    context: Context,
    private val currentChallenge: QuranChallenge,
) :
    Dialog(context) {

    private lateinit var mCurrentChallengeLevelDesc: TextView
    private lateinit var mRewardsTv: TextView
    private lateinit var mQuranNamesArr : Array<String>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
    }


    private fun init() {
        setContentView(
            LayoutInflater.from(context).inflate(R.layout.dialog_challenge_result, null)
        )

        mCurrentChallengeLevelDesc = findViewById(R.id.tv_challenge_level_tip)
        mRewardsTv = findViewById(R.id.tv_rewards)
        val challengeDescStr = context.resources.getString(R.string.str_challenge_tip)
        mQuranNamesArr = context.resources.getStringArray(R.array.quran_name_arr)
        mCurrentChallengeLevelDesc.text =
            String.format(
                Locale.getDefault(),
                challengeDescStr,
                mQuranNamesArr[currentChallenge?.chapterIndex!!],
                currentChallenge.duration
            )
        mRewardsTv.text =
            String.format(Locale.ENGLISH, "+%d", currentChallenge.rewardValue)


        val lp = window!!.attributes
        lp.width = 240
        lp.height = 240
        window!!.attributes = lp
    }

}